<template>
	<div class="force_amend_wrapper">
		<div class="form">
			<h4>是否强制修改</h4>
			<el-switch v-model="isTimingForce" active-value="1" inactive-value="2" @change="handleSaveForceConfig"></el-switch>
		</div>
		<div class="tips">开启之后，输入几次错误后会进行登录锁定</div>
		<div class="set" v-if="isTimingForce === '1'">
			<span>强制修改周期</span>
			<sw-number-input v-model="timingForceLen" size="mini"></sw-number-input>
			<font>天</font>
			<el-button size="mini" type="primary" @click="handleSaveForceConfig">保存</el-button>
		</div>
	</div>
</template>

<script>
	import { mapGetters } from 'vuex';
	import { updateTimingSetting } from '@/api/system/tbSysSite';
	export default {
		data() {
			return {
				isTimingForce: '1',
				timingForceLen: '30'
			};
		},
		computed: {
			...mapGetters(['siteInfo'])
		},
		mounted() {
			this.isTimingForce = this.siteInfo.isTimingForce;
			this.timingForceLen = this.siteInfo.timingForceLen;
		},
		methods: {
			async handleSaveForceConfig() {
				let params = { id: this.siteInfo.id, isTimingForce: this.isTimingForce, timingForceLen: this.timingForceLen };
				let result = await updateTimingSetting(params).then((res) => res.data);
				if (result.code === '0') {
					this.$message.success('保存设置成功');
					this.$store.dispatch('getSiteBaseInfo');
				} else {
					this.$message.error('保存设置失败');
				}
			}
		}
	};
</script>

<style lang="scss" scoped>
	.force_amend_wrapper {
		display: flex;
		flex-direction: column;
		flex: 1;
		padding: 16px;
		overflow: hidden;

		.form {
			display: flex;
			align-items: center;

			h4 {
				margin-right: 10px;
				line-height: 1;
			}
		}

		.tips {
			font-size: 14px;
			line-height: 1;
			color: #909399;
			margin-top: 10px;
		}

		.set {
			display: flex;
			align-items: center;
			margin-top: 12px;

			span {
				margin-right: 10px;
			}

			font {
				margin-left: 10px;
			}

			.el-input__inner {
				padding: 0 10px;
			}

			.el-input {
				width: 60px;
				font-size: 14px;
				text-align: center;
			}

			.el-button {
				margin-left: 10px;
			}
		}
	}
</style>